{include file="public/head"}
<style type="text/css" media="screen">
    .x-body {
        min-width: 1100px;
    }
    body {
        overflow-x: scroll;
    }
    .x-right button{
        display: initial;
    }
</style>
<body>
<div class="x-body">
    <div class="lotus-nav" style="height:30px">
        <button class="layui-btn layui-btn-sm" onclick="x_admin_show('添加违禁词','illegalWordsAdd.html','500','300')">
            <i class="layui-icon layui-icon-add-circle"></i>添加违禁词
        </button>

        <div class="layui-input-inline" style="width: 350px;">
            <input id="words" name="words" class="layui-input lotus-input" placeholder="请输入搜索违禁词" value="{$Think.get.words}">
        </div>
        <button class="layui-btn layui-btn-sm" onclick="search()">
            <i class="layui-icon layui-icon-search"></i>搜索
        </button>
        <button class="layui-btn layui-btn-sm layui-btn-danger" onclick="delAll()">
            <i class="layui-icon"></i>批量删除
        </button>

        <span class="x-right">共有数据:<i class="i_count">{$data->total()}</i>条
            <button onclick="javascript:location.reload()" class="layui-btn-default ">
                <i class="layui-icon layui-icon-refresh"></i>
            </button>
        </span>
    </div>



    <table class="layui-table">
        <thead>
        <tr>
            <th style="width: 75px;text-align:center">
                <div class="header layui-form-checkbox" lay-skin="primary"><i class="layui-icon">&#xe605;</i></div>
            </th>
            <th>违禁词</th>
            <th style="width: 120px;text-align:center">创建时间</th>
            <th style="width: 40px;text-align:center">操作</th>
        </tr>
        </thead>
        <tbody>
        {volist name="data" id="vo"}
        <tr>
            <td style="text-align:center">
                <div class="layui-form-checkbox" lay-skin="primary" data-id='{$vo.id}'>
                    <i class="layui-icon">&#xe605;</i>
                </div>
                {if $Think.get.page == ''}
                {$i}
                {else/}
                {$i+$data->listRows()*($Think.get.page-1)}
                {/if}
            </td>
            <td>{$vo.words}</td>
            <td style="text-align:center">{$vo['timestamp']|date="Y-m-d H:i",###}</td>
            <td style="text-align:center">
                <button onclick="del(this,'{$vo.id}')" class="layui-btn layui-btn-xs layui-btn-danger">
                    删除
                </button>
            </td>
        </tr>
        {/volist}
        </tbody>
    </table>
    <div class="page">
        <div>
            {$data->render()}
        </div>
    </div>
</div>
</body>
{include file="public/foot"}
<script>
    function search() {
        var words = $("#words").val();
        location.href = "illegalWords.html?words=" + words;
    }
    //删除所有
    function delAll() {
        var data = tableCheck.getData();
        if (data.length == 0) {
            layer.msg("请选择需要删除的违禁词");
            return false;
        }
        layer.confirm('确认要全部删除吗？', function (index) {
            layer.load(1);
            //捉到所有被选中的，发异步进行删除
            $.post("{:url('admin/product/illegalWordsDel')}", {id: data}, function (data) {
                layer.closeAll('loading');
                if (data.code == 1) {
                    layer.msg(data.msg, {icon: 1, time: 1000}, function () {
                        location.reload();
                    });
                } else {
                    layer.msg(data.msg, {icon: 2, time: 1000});
                }

            });
        });
    }

    function del(obj, id) {
        var count = $(".i_count")[0].innerText;
        layer.confirm('确认要删除吗？', function (index) {
            layer.load(1);
            //捉到所有被选中的，发异步进行删除
            $.post("{:url('admin/product/illegalWordsDel')}", {id: id}, function (data) {
                layer.closeAll('loading');
                if (data.code == 1) {
                    layer.msg(data.msg, {icon: 1, time: 1000}, function () {
                        $(obj).parents('tr').remove();
                        $(".i_count").html(count - 1);
                    });
                } else {
                    layer.msg(data.msg, {icon: 2, time: 1000});
                }

            });
        });
    }
</script>
